﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace GabageFactory.Models
{
    public class RoleReposity : Reposity
    {
        public IEnumerable<Role> ListRoles()
        {
            var roles = from r in _dataContext.Roles
                            select r;
            foreach (Role r in roles)
            {
                yield return r;
            }
        }

        public Role GetRoleById(long id)
        {
            var role = from r in _dataContext.Roles
                          where id == r.Id
                          select r;

            return role.First();
        }

        public Role CreateRole(Role role)
        {
            _dataContext.Roles.InsertOnSubmit(role);
            SubmitChanges();
            return role;
        }

        public bool DeleteRole(Role role)
        {
            _dataContext.Roles.DeleteOnSubmit(role);
            return true;
        }

        public Role EditRole(Role role)
        {
            SubmitChanges();
            return role;
        }
    }
}